package com.yayo.mangement.security.config;

import org.springframework.context.annotation.Configuration;

import java.util.*;

/**
 * @WhiteListConfig: 接口白名单
 * @author: Yayo
 * @date: 2022/9/3 22:22
 */
@Configuration
public class WhiteListConfig {
    public static final List<String> WHITE_LIST = new ArrayList();

    public WhiteListConfig(){
        WHITE_LIST.add("/api/sys/login");
        WHITE_LIST.add("/api/sysMenu/list");
        WHITE_LIST.add("/api/sys/user/initPassword");
        WHITE_LIST.add("/api/convert");
        WHITE_LIST.add("/favicon.ico");
        WHITE_LIST.add("/api/sys/xlsx/export/*");
    }

    public static boolean checkWhiteList(String uri){
        String findFirst = WHITE_LIST.stream().filter(white -> {
            if (white.contains("*")){
                return uri.startsWith(white.substring(0, white.indexOf("*")));
            }else {
                return uri.equals(white);
            }
        }).findFirst().orElse(null);
        return findFirst == null ? false : true;
    }

    public static String[] getWhiteListString(){
        return  WHITE_LIST.toArray(new String[WHITE_LIST.size()]);
    }
}
